package com.pai4j.zwiki.domain.entity;

import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;

import java.time.LocalDateTime;

/**
 * 项目分析实体
 * 存储GitHub项目的分析任务信息
 *
 * @author pai4j
 * @since 2025-10-12
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Entity
@Table(name = "pai4j_project_analysis", indexes = {
        @Index(name = "idx_user_id", columnList = "userId"),
        @Index(name = "idx_status", columnList = "status"),
        @Index(name = "idx_created_at", columnList = "createdAt")
})
public class ProjectAnalysisEntity {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    /**
     * 分析任务唯一标识
     */
    @Column(nullable = false, unique = true, length = 64)
    private String taskId;

    /**
     * 用户ID
     */
    @Column(nullable = false)
    private Long userId;

    /**
     * 项目名称
     */
    @Column(nullable = false, length = 255)
    private String projectName;

    /**
     * GitHub仓库URL
     */
    @Column(length = 512)
    private String repositoryUrl;

    /**
     * 项目来源类型：github, zip
     */
    @Column(nullable = false, length = 20)
    private String sourceType;

    /**
     * 本地工作目录路径
     */
    @Column(length = 512)
    private String workspacePath;

    /**
     * 分析状态：pending, cloning, analyzing, generating, completed, failed
     */
    @Column(nullable = false, length = 20)
    private String status;

    /**
     * 进度百分比 0-100
     */
    @Column(nullable = false)
    private Integer progress;

    /**
     * 当前处理步骤描述
     */
    @Column(length = 255)
    private String currentStep;

    /**
     * 项目编程语言
     */
    @Column(length = 50)
    private String primaryLanguage;

    /**
     * 项目总文件数
     */
    private Integer totalFiles;

    /**
     * Java文件数
     */
    private Integer javaFiles;

    /**
     * 总代码行数
     */
    private Long totalLines;

    /**
     * 分析结果（JSON格式）
     */
    @Column(columnDefinition = "LONGTEXT")
    private String analysisResult;

    /**
     * 错误信息
     */
    @Column(columnDefinition = "TEXT")
    private String errorMessage;

    /**
     * 生成的论文文件路径
     */
    @Column(length = 512)
    private String thesisFilePath;

    /**
     * 生成的架构图文件路径
     */
    @Column(length = 512)
    private String diagramFilePath;

    /**
     * 用户是否提供了自定义模板
     */
    @Column(nullable = false)
    private Boolean hasCustomTemplate;

    /**
     * 自定义模板文件路径
     */
    @Column(length = 512)
    private String customTemplatePath;

    /**
     * 创建时间
     */
    @CreationTimestamp
    @Column(nullable = false, updatable = false)
    private LocalDateTime createdAt;

    /**
     * 更新时间
     */
    @UpdateTimestamp
    @Column(nullable = false)
    private LocalDateTime updatedAt;

    /**
     * 完成时间
     */
    private LocalDateTime completedAt;
}

